define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ltday/index' + location.search,
                    add_url: 'ltday/add',
                    edit_url: 'ltday/edit',
                    //del_url: 'ltday/del',
                    multi_url: 'ltday/multi',
                    import_url: 'ltday/import',
                    table: 'ltday',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pageSize: 20,
                showExport: false,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'dx_date', title: __('Dx_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'zhichu_money', title: __('Zhichu_money'), operate:false},
                        {field: 'shouru_money', title: __('Shouru_money'), operate:false},
                        {field: 'jieyu', title: __('结余'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('明细'),
                            operate: false,
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('收入明细'),
                                    title: __('明细'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'ltdaylog/index?ctype=1&log_date={dx_date}',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __('支出明细'),
                                    title: __('明细'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'ltdaylog/index?ctype=2&log_date={dx_date}',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'shouli.name', title: __('Shouli.name'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.shouru);
                $("#price").text(data.zhichu);
                $("#jieyu").text(data.jieyu);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
